﻿using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SurveillancePro.Base.Events;
using SurveillancePro.Base.Common;


namespace DeviceMgtModule
{
    /// <summary>
    /// 设备管理模块
    /// </summary>
    public class DeviceMgtModule : IModule
    {
        #region 常量

        private readonly IEventAggregator _eventAggregator;
        private readonly IUnityContainer _container;

        #endregion

        #region 构造函数

        public DeviceMgtModule(IEventAggregator eventAggregator, IUnityContainer container)
        {
            this._eventAggregator = eventAggregator;
            EnvCommonUtility.EnvUtilities.EnvContainer = this._container = container;
        }

        #endregion

        #region 方法

        /// <summary>
        /// 注册模块内的事件
        /// </summary>
        public void Subcribe()
        {
            // 接收主模块的消息(ViewModel_Shell)
            OpenModelEvent openEvent = _eventAggregator.GetEvent<OpenModelEvent>();
            openEvent.Subscribe(Show, ThreadOption.UIThread, true,
                x => x.ModelName == this.GetType().Name);
        }

        /// <summary>
        /// 事件回调函数
        /// </summary>
        /// <param name="arg"></param>
        public void Show(OpenModelEventArg arg)
        {
            // 注册视图类型
            this._container.RegisterType<object, Views.View_DeviceTree>(ViewNames.DeviceMgtModule_DeviceTree);
            this._container.RegisterType<object, Views.View_DeviceManagement>(ViewNames.DeviceMgtModule_DeviceManagement);
        }

        #endregion

        #region IModule 成员

        public void Initialize()
        {
            Subcribe(); // 注册模块事件
        }

        #endregion
    }
}
